//<!-- License -->
package eu.datafusion.log4soa.model;

import static javax.persistence.EnumType.ORDINAL;

import java.util.Date;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import eu.datafusion.log4soa.model.referencedata.Application;
import eu.datafusion.log4soa.model.referencedata.Operation;
import eu.datafusion.log4soa.model.referencedata.Service;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.Basic;

@Entity
@Table(name = "LOG_MESSAGE")
@Cacheable
public class LogMessage {

	/**
	 * entity id -  primary key
	 */
	@Id
	@Column(name = "ID")
	private long id;
	
	/**
	 * Required property <tt>application</tt>
	 */
	@ManyToOne
	@JoinColumn(name = "APP_ID", referencedColumnName = "ID", updatable = false, nullable = false)
	private Application application = null;
	
	/**
	 * Required property <tt>service</tt>
	 */
	@ManyToOne
	@JoinColumn(name = "SERVICE_ID", referencedColumnName = "ID", updatable = false, nullable = false)
	private Service service = null;

	/**
	 * Required property <tt>operation</tt>
	 */
	@ManyToOne
	@JoinColumn(name = "OPERATION_ID", referencedColumnName = "ID", updatable = false, nullable = false)
	private Operation operation = null;
	
	/**
	 * Required property <tt>dataProtection</tt>
	 */
	@Enumerated(ORDINAL)
	@Column(name = "DATAPROTECT")
	@Basic(optional = false)
	private DataProtection dataProtection = DataProtection.UNPROTECTED;
	
	/**
	 * Required property <tt>logLevel</tt>
	 */
	@Enumerated(ORDINAL)
	@Column(name = "LOGLEVEL")
	@Basic(optional = false)
	private LogLevel logLevel = null;
	
	/**
	 * Required property <tt>messageTimestamp</tt>
	 */
	@Temporal( TemporalType.TIMESTAMP)
	@Column(name = "MSG_TSTAMP")
	@Basic(optional = false)
	private Date messageTimestamp;
	
	/**
	 * property <tt>content</tt> contains log message content encrypted or archived depending from dataProtection
	 */
	@Lob
	@Column(name = "CONTENT")
	@Basic(optional = false)
	private byte[] content;
	
	/**
	 * property <tt>flowId</tt> is used to correlate operation invocations in flow
	 */
	@Column(name = "FLOW_ID")
	@Basic(optional = false)
	private String flowId;
	
	
	// operation invocation id is used to correlate log messages for operation invocation
	@Column(name = "INVOC_ID")
	@Basic(optional = false)
	private String invocationId;
	/**
	 * Getter of the property <tt>id</tt>
	 * @return  Returns the id.
	 */
	public long getId() {
		return id;
	}

	/** 
	 * Getter of the property <tt>application</tt>
	 * @return  Returns the application.
	 */
	public Application getApplication() {
		return application;
	}

	/** 
	 * Getter of the property <tt>service</tt>
	 * @return  Returns the service.
	 */
	public Service getService() {
		return service;
	}

	/**
	 * Getter of the property <tt>operation</tt>
	 * @return  Returns the operation.
	 */
	public Operation getOperation() {
		return operation;
	}


	/** 
	 * Getter of the property <tt>dataProtection</tt>
	 * @return  Returns the dataProtection.
	 */
	public DataProtection getDataProtection() {
		return dataProtection;
	}
	
	/** 
	 * Getter of the property <tt>logLevel</tt>
	 * @return  Returns the logLevel.
	 */
	public LogLevel getLogLevel() {
		return logLevel;
	}
	
	/** 
	 * Getter of the property <tt>messageTimestamp</tt>
	 * @return  Returns the messageTimestamp.
	 */
	public Date getMessageTimestamp() {
		return messageTimestamp;
	}

	/** 
	 * Getter of the property <tt>content</tt>
	 * @return  Returns the log message content compressed or encrypted depending from dataProtection.
	 */
	public byte[] getContent() {
		return content;
	}

	/**
	 * Setter of the property <tt>content</tt>
	 * @param  log message content compressed or encrypted depending from dataProtection.
	 */
	public void setContent(byte[] content) {
		this.content = content;
	}

	
	/**
	 * Getter of the property <tt>flowId</tt>  used to correlate operation invocations in flow
	 * @return
	 */
	public String getFlowId() {
		return flowId;
	}

	/**
	 * Getter of the property <tt>invocationId</tt> used to correlate log messages for operation invocation
	 * @return
	 */
	public String getInvocationId() {
		return invocationId;
	}
	
	/**
	 * 
	 */
	
	
}
